package com.digitalchina.lxnsy.api;

import android.app.Activity;
import android.os.Handler;

import com.digitalchina.lxnsy.constant.MSG;
import com.digitalchina.lxnsy.constant.URL;
import com.digitalchina.lxnsy.toolkit.OkHttpUtil;
import com.digitalchina.lxnsy.xml.UserXML;
import com.lzy.okhttputils.model.HttpParams;

/**
 * ================================================
 * 项目名称：BigData
 * 类描述：
 * 包名：com.digitalchina.bigdata.api
 * 创建人：郑皓
 * 创建时间：2017/1/3 18:56
 * 修改备注：
 * ================================================
 */
public class BusinessEvaluate {

    /**
     * 评价接口
     *
     * @param activity
     * @param orderNo            订单号
     * @param accordStore        符合度评分
     * @param serviceScore       服务态度评分
     * @param isAnonymity        是否匿名 1 是 0否
     * @param evaluateProductStr 商品评价列表json 格式
     * @param poHandler
     */
    public static void mobileEvaluateOrder(Activity activity, String orderNo, String accordStore, String serviceScore, String isAnonymity, String evaluateProductStr, Handler poHandler) {

        HttpParams params = new HttpParams();
        params.put("orderNo", orderNo);
        params.put("accordStore", accordStore);
        params.put("serviceScore", serviceScore);
        params.put("isAnonymity", isAnonymity);
        params.put("evaluateProductStr", evaluateProductStr);
        params.put("useraccId", UserXML.getUserId(activity));

        OkHttpUtil.post(activity, URL.URL_EVALUATE_ORDER, "请稍候", params, poHandler, MSG.MSG_EVALUATE_ORDER_SUCCESS, MSG.MSG_EVALUATE_ORDER_FIELD);

    }

    /**
     * 评价列表
     *
     * @param activity
     * @param productId 商品id
     * @param evaType   评价类型  0-全部 1-好评 2-中评 3-差评
     * @param offset    当前页数
     * @param limit     每页行数
     * @param handler
     */
    public static void findProductEvalutionList(Activity activity, String productId, String evaType, String offset, String limit, Handler handler) {

        HttpParams params = new HttpParams();
        params.put("productId", productId);
        params.put("evaType", evaType);
        params.put("offset", offset);
        params.put("limit", limit);

        OkHttpUtil.post(activity, URL.URL_FIND_PRODUCT_EVALUTION_LIST, "", params, handler, MSG.MSG_FIND_PRODUCT_EVALUTION_LIST_SUCCESS, MSG.MSG_FIND_PRODUCT_EVALUTION_LIST_FIELD);

    }

    /**
     * 各类型评价个数 (平均分 + "|" + 全部数量 + "|" + 好评数量 + "|" + 中评数量 + "|" + 差评数量)
     *
     * @param activity
     * @param productId 商品id
     * @param handler
     */
    public static void findProductEvalutionTypeCount(Activity activity, String productId, Handler handler) {

        HttpParams params = new HttpParams();
        params.put("productId", productId);

        OkHttpUtil.post(activity, URL.URL_FIND_PRODUCT_EVALUTION_TYPE_COUNT, "", params, handler,
                MSG.MSG_EVALUATION_TYPE_COUNT_SUCCESS, MSG.MSG_EVALUATION_TYPE_COUNT_FIELD);

    }

    /**
     * 通过订单号获取所有产品评分
     *
     * @param activity
     * @param orderNo  订单号
     * @param handler
     */
    public static void getProductEvaluateByOrderNo(Activity activity, String orderNo, Handler handler) {

        HttpParams params = new HttpParams();
        params.put("orderNo", orderNo);

        OkHttpUtil.post(activity, URL.URL_GET_PRODUCT_EVALUATE_BY_ORDER_NO, "", params, handler,
                MSG.MSG_GET_PRODUCT_EVALUATE_BY_ORDER_NO_SUCCESS, MSG.MSG_GET_PRODUCT_EVALUATE_BY_ORDER_NO_FIELD);

    }

    /**
     * 获取订单中卖家的评价
     *
     * @param activity
     * @param orderNo  订单号
     * @param sellerId 卖家ID
     * @param handler
     */
    public static void getSellerScoreByOrderNo(Activity activity, String orderNo, String sellerId, Handler handler) {

        HttpParams params = new HttpParams();
        params.put("orderNo", orderNo);
        params.put("sellerId", sellerId);

        OkHttpUtil.post(activity, URL.URL_GET_SELLER_SCORE_BY_ORDER_NO, "", params, handler,
                MSG.MSG_GET_SELLER_SCORE_BY_ORDER_NO_SUCCESS, MSG.MSG_GET_SELLER_SCORE_BY_ORDER_NO_FIELD);

    }

    /**
     * 获取订单中卖家的评价
     *
     * @param activity
     * @param evaluateProductId 商品评论ID
     * @param content           评论内容
     * @param handler
     */
    public static void addAdditionEvaContent(Activity activity, String evaluateProductId, String content, Handler handler) {

        HttpParams params = new HttpParams();
        params.put("evaluateProductId", evaluateProductId);
        params.put("content", content);

        OkHttpUtil.post(activity, URL.URL_ADD_ADDITION_EVA_CONTENT, "请稍候...", params, handler,
                MSG.MSG_ADD_ADDITION_EVA_CONTENT_SUCCESS, MSG.MSG_ADD_ADDITION_EVA_CONTENT_FIELD);

    }

    /**
     * 获取服务评价选项
     *
     * @param activity
     * @param handler
     */
    public static void getAssessOpts(Activity activity, Handler handler) {

        HttpParams params = new HttpParams();

        OkHttpUtil.post(activity, URL.URL_GET_ASSESS_OPTS, "", params, handler,
                MSG.MSG_GET_ASSESS_OPTS_SUCCESS, MSG.MSG_GET_ASSESS_OPTS_FIELD);

    }


    /**
     * 获取服务评价ID
     *
     * @param activity
     * @param expertId     专家ID
     * @param firstAskTime 首次提问时间 格式2017-03-08 23:24:42
     * @param handler
     */
    public static void getAssessId(Activity activity, String expertId, String firstAskTime, Handler handler) {

        HttpParams params = new HttpParams();
        params.put("expertId", expertId);
        params.put("userId", UserXML.getUserId(activity));
        params.put("firstAskTime", firstAskTime);

        OkHttpUtil.post(activity, URL.URL_GET_ASSESS_ID, "", params, handler,
                MSG.MSG_GET_ASSESS_ID_SUCCESS, MSG.MSG_GET_ASSESS_ID_FIELD);

    }

    /**
     * 保存历史问题
     *
     * @param activity
     * @param expertId 专家ID
     * @param question 问题
     * @param handler
     */
    public static void saveHisQuestion(Activity activity, String expertId, String question, String firstAskTime, Handler handler) {

        HttpParams params = new HttpParams();
        params.put("userId", UserXML.getUserId(activity));
        params.put("expertId", expertId);
        params.put("firstAskTime", firstAskTime);
        params.put("question", question);

        OkHttpUtil.post(activity, URL.URL_SAVE_HIS_QUESTION, "", params, handler,
                MSG.MSG_SAVE_HIS_QUESTION_SUCCESS, MSG.MSG_SAVE_HIS_QUESTION_FIELD);

    }

    /**
     * 更新历史问题
     *
     * @param activity
     * @param userId   用户ID (专家用户才会调用此接口)
     * @param handler
     */
    public static void updateHisQuestion(Activity activity, String userId, Handler handler) {

        HttpParams params = new HttpParams();
        params.put("userId", userId);
        params.put("expertId", UserXML.getUserId(activity));

        OkHttpUtil.post(activity, URL.URL_UPDATE_HIS_QUESTION, "", params, handler,
                MSG.MSG_UPDATE_HIS_QUESTION_SUCCESS, MSG.MSG_UPDATE_HIS_QUESTION_FIELD);

    }

    /**
     * 保存服务评价
     *
     * @param activity
     * @param score    评价等级
     * @param content  评价内容
     * @param optCheck 评价选项 optCheck[0]=000
     * @param assessId 评价id 可为空
     * @param handler
     */
    public static void saveServiceAssess(Activity activity, String score, String content, String optCheck[], String assessId, Handler handler) {

        HttpParams params = new HttpParams();
        params.put("userId", UserXML.getUserId(activity));
        params.put("score", score);
        params.put("content", content);
        params.put("id", assessId);

        for (int i = 0; i < optCheck.length; i++) {
            params.put("optCheck[" + i + "]", optCheck[i]);
        }

        OkHttpUtil.post(activity, URL.URL_SAVE_SERVICE_ASSESS, "", params, handler, MSG.MSG_SAVE_SERVICE_ASSESS_SUCCESS, MSG.MSG_SAVE_SERVICE_ASSESS_FIELD);

    }


    /**
     * 提交培训评价
     *
     * @param activity
     * @param trainId              培训id
     * @param trainSuggestion      培训建议
     * @param scoreForExpertTrain  对专家培训评价分数
     * @param scoreForTrainContent 对培训内容评价分数
     * @param scoreForSponsor      对主办方评价分队
     * @param handler
     */
    public static void evaluateForTrain(Activity activity, String trainId, String trainSuggestion, String scoreForExpertTrain, String scoreForTrainContent, String scoreForSponsor, Handler handler) {

        HttpParams params = new HttpParams();
        params.put("useraccId", UserXML.getUserId(activity));
        params.put("trainId", trainId);
        params.put("trainSuggestion", trainSuggestion);
        params.put("scoreForExpertTrain", scoreForExpertTrain);
        params.put("scoreForTrainContent", scoreForTrainContent);
        params.put("scoreForSponsor", scoreForSponsor);


        OkHttpUtil.post(activity, URL.URL_EVALUATE_FOR_TRAIN, "", params, handler, MSG.MSG_EVALUATE_FOR_TRAIN_SUCCESS, MSG.MSG_EVALUATE_FOR_TRAIN_FIELD);

    }

    /**
     * 新版提交培训评价
     *
     * @param activity
     * @param trainId    培训id
     * @param code       选项集合(数组)
     * @param suggestion 培训建议
     * @param handler
     */
    public static void evaluateForTrainNew(Activity activity, String trainId, String code[], String suggestion, Handler handler) {

        HttpParams params = new HttpParams();
        params.put("useraccId", UserXML.getUserId(activity));
        params.put("trainId", trainId);
        params.put("courseArrangeCode", code[0]);
        params.put("teachMethodCode", code[1]);
        params.put("teachMeansCode", code[2]);
        params.put("expressionSkillCode", code[3]);
        params.put("teachInteractionCode", code[4]);
        params.put("organizeWorkCode", code[5]);
        params.put("suggestion", suggestion);


        OkHttpUtil.post(activity, URL.URL_EVALUATE_FOR_TRAIN_NEW, "", params, handler, MSG.MSG_EVALUATE_FOR_TRAIN_SUCCESS, MSG.MSG_EVALUATE_FOR_TRAIN_FIELD);

    }


    /**
     * 所有评价列表
     *
     * @param activity
     * @param handler
     */
    public static void allEvaluateList(Activity activity, String page, String limit, Handler handler) {

        HttpParams params = new HttpParams();
        params.put("useraccId", UserXML.getUserId(activity));
        params.put("page", page);
        params.put("limit", limit);


        OkHttpUtil.post(activity, URL.URL_ALL_EVALUATE_LIST, "", params, handler, MSG.MSG_ALL_EVALUATE_LIST_SUCCESS, MSG.MSG_ALL_EVALUATE_LIST_FIELD);

    }


    /**
     * 培训评价详情
     *
     * @param activity
     * @param trainId  培训id
     * @param handler
     */
    public static void getEvaluateDetails(Activity activity, String trainId, Handler handler) {

        HttpParams params = new HttpParams();
        params.put("useraccId", UserXML.getUserId(activity));
        params.put("trainId", trainId);

        OkHttpUtil.post(activity, URL.URL_GET_EVALUATE_DETAILS, "", params, handler, MSG.MSG_ALL_EVALUATE_LIST_SUCCESS, MSG.MSG_ALL_EVALUATE_LIST_FIELD);

    }

    /**
     * 新版培训评价详情
     *
     * @param activity
     * @param trainId
     * @param handler
     */
    public static void getEvaluateDetailsNew(Activity activity, String trainId, Handler handler) {

        HttpParams params = new HttpParams();
        params.put("useraccId", UserXML.getUserId(activity));
        params.put("trainId", trainId);

        OkHttpUtil.post(activity, URL.URL_GET_EVALUATE_DETAILS_NEW, "正在加载...", params, handler, MSG.MSG_ALL_EVALUATE_LIST_SUCCESS, MSG.MSG_ALL_EVALUATE_LIST_FIELD);

    }

    /**
     * 获取新版培训评价选项
     *
     * @param activity
     * @param handler
     */
    public static void toEvaluate(Activity activity, Handler handler) {

        HttpParams params = new HttpParams();

        OkHttpUtil.post(activity, URL.URL_TO_EVALUATE, "正在获取...", params, handler, MSG.MSG_TO_EVALUATE_SUCCESS, MSG.MSG_TO_EVALUATE_FIELD);

    }
}
